package index.query;

import engine.query.Plan;
import engine.query.Scan;
import engine.query.TableScan;
import storage.record.Schema;



public class LookupPlan implements Plan {
	private Plan rp, tp;
	private Schema sch = new Schema();


	public LookupPlan(Plan rp, Plan tp) {
		this.rp = rp;
		this.tp = tp;
		sch.addAll(rp.schema());
		sch.addAll(tp.schema());
	}

	

	public Scan open() {
		RidScan rs = (RidScan) rp.open();
		TableScan ts = (TableScan) tp.open();
		return new LookupScan(rs, ts);
	}



	public int blocksAccessed() {
		return rp.blocksAccessed() + rp.recordsOutput();
	}


	public int recordsOutput() {
		return rp.recordsOutput();
	}



	public int distinctValues(String fldname) {
		if (rp.schema().hasField(fldname))
			return rp.distinctValues(fldname);
		else
			return tp.distinctValues(fldname);
	}


	public Schema schema() {
		return sch;
	}
}
